package com.mlz.controller;

import com.mlz.pojo.Dept;
import com.mlz.pojo.Result;
import com.mlz.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


//日志输出
@Slf4j
//一级目录: 定义模块
@RequestMapping("/depts")
//部门管理的控制器类
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;

    //@GetMapping("/depts")
    //二级目录: 定位具体处理资源的方法
    @GetMapping
    public Result list(){
        log.info("查询所有部门数据");
        //调用service层业务方法
        List<Dept> deptList = deptService.list();

        return Result.success(deptList);
    }


//    @DeleteMapping("/depts/{id}")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) throws Exception {
        //日志记录
        log.info("根据id删除部门");
        //调用service的功能
        deptService.delete(id);
        return Result.success();
    }


    //@PostMapping("/depts")
    @PostMapping
    public Result add(@RequestBody Dept dept){
        //日志记录
        log.info("新增部门:{}",dept);
        //调用service层添加功能
        deptService.add(dept);
        return Result.success();
    }















}
